package com.example.demo.mongo.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

/**
 * @Author: wn
 * @Date: 2021/8/6 16:48
 * @Version 1.0
 * @Note
 */
/*指定集合*/
@Document(collection = "user")
@ApiModel(value = "测试实体user")
/*
建立索引，提高查询速度
*/
@CompoundIndexes(
        {
                @CompoundIndex(name = "name_createTime", def = "{'name':1,'createTime':-1}")
        })
public class User {

    @Id
    private String userId;
//    @Indexed(unique = true)
    @ApiModelProperty(value = "姓名", example = "张飞")
    private String name;
    private Integer age;
    private Date createTime = new Date();

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
